package com.xl.rentkeeper.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Administrator on 2015/7/20.
 */
public class TimeUtils {

    public static String getDate() {
        String time = null;
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        time = df.format(new Date());
        return time;
    }

    public static String fmtDate(long time) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date date = new Date();
        date.setTime(time);
        String timestr = df.format(date);
        return timestr;
    }
    public static String fmtDateToPoint(long time) {
        DateFormat df = new SimpleDateFormat("yyyy.MM.dd");
        Date date = new Date();
        date.setTime(time);
        String timestr = df.format(date);
        return timestr;
    }
    public static String fmtDateYMD(long time) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        date.setTime(time);
        String timestr = df.format(date);
        return timestr;
    }
    public static String fmtDateFull(long time) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        date.setTime(time);
        String timestr = df.format(date);
        return timestr;
    }
    public static String getDateHHmmss() {
        String time = null;
        DateFormat df = new SimpleDateFormat("HH:mm:ss");
        time = df.format(new Date());
        return time;
    }

    /*时间戳转换成字符窜*/
    public static String getDateToString(long time) {
        Date d = new Date(time);
        SimpleDateFormat sf = new SimpleDateFormat("yyyy年MM月dd日");
        return sf.format(d);
    }

    /*将字符串转为时间戳*/
    public static long getStringToDate(String time) {
        SimpleDateFormat  sdf = new SimpleDateFormat("yyyy年MM月dd日");
        Date date = new Date();
        try{
            date = sdf.parse(time);
        } catch(ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return date.getTime();
    }

    public static long getTodayStart(){
        Date date = new Date();
        date.setTime(System.currentTimeMillis());
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        return c.getTime().getTime();
    }
    public static long getTodayEnd(){
        Date date = new Date();
        date.setTime(System.currentTimeMillis());
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.HOUR_OF_DAY, 23);
        c.set(Calendar.MINUTE, 59);
        c.set(Calendar.SECOND, 59);
        return c.getTime().getTime();
    }
     public static long dayToTimeStamp(){
        return 24*60*60*1000;
     }

}
